package com.burgeon.backend.SHOPBACKEND.controller;

import com.burgeon.backend.SHOP.entity.Recommend;
import com.burgeon.backend.SHOP.entity.RecommendConfig;
import com.burgeon.backend.SHOP.entity.RecommendSwitch;
import com.burgeon.backend.SHOP.entity.RecommendVo;
import com.burgeon.backend.SHOPBACKEND.service.BackendRecommendService;
import com.burgeon.backend.stsutil.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;

@CrossOrigin
@RestController
@RequestMapping("recommend")
public class BackendRecommendController extends BaseController {
    @Autowired
    private BackendRecommendService backendRecommendService;

    /**
     * 获取推荐奖励信息
     * @param account
     * @return
     */
    @RequestMapping("getRecommendConfig")
    public ResponseResult<RecommendConfig> getRecommendConfig(String account){
        RecommendConfig data = backendRecommendService.getRecommendConfigByAccount(account);
        return new ResponseResult<>(SUCCESS,data);
    }

    /**
     * 新增配置信息
     * @param name
     * @param account
     * @return
     */
    @RequestMapping("addRecommendConfig")
    public ResponseResult<Integer> addRecommendConfig(MultipartFile recommendImg,MultipartFile newImg,String name,String account){
        Integer data = backendRecommendService.addRecommendCode(recommendImg,newImg, name, account);
        return new ResponseResult<>(SUCCESS,data);
    }

    /**
     * 修改配置信息
     * @param name
     * @param account
     * @return
     */
    @RequestMapping("updateRecommendConfig")
    public ResponseResult<Integer> updateRecommendConfig(MultipartFile recommendImg,MultipartFile newImg,String name,String account){
        Integer data = backendRecommendService.updateRecommendCode(recommendImg,newImg, name, account);
        return new ResponseResult<>(SUCCESS,data);
    }

    /**
     * 获取推荐奖励信息
     * @param account
     * @return
     */
    @RequestMapping("getSwitch")
    public ResponseResult<RecommendSwitch> getSwitch(String account){
        RecommendSwitch data = backendRecommendService.findRecommendSwitchByAccount(account);
        return new ResponseResult<>(SUCCESS,data);
    }

    /**
     * 修改奖励值
     * @param rSwitch1 推荐优惠券
     * @param rValue1
     * @param rSwitch2 推荐积分
     * @param rValue2
     * @param rSwitch3 新用户优惠券
     * @param rValue3
     * @param rSwitch4 新用户积分
     * @param rValue4
     * @param account
     * @return
     */
    @RequestMapping("updateSwitch")
    public ResponseResult<Integer> updateSwitch(String rSwitch1, String rValue1, String rSwitch2, String rValue2,
                                                String rSwitch3, String rValue3, String rSwitch4, String rValue4,
                                                String account){
        System.err.println(account);
        Integer data = backendRecommendService.updateRecommendSwitch(rSwitch1, rValue1, rSwitch2, rValue2,
                rSwitch3, rValue3, rSwitch4, rValue4, account);
        return new ResponseResult<>(SUCCESS,data);
    }

    /**
     * 获取推荐成功列表
     * @param account
     * @param page
     * @return
     */
    @RequestMapping("getRecommend")
    public ResponseResult<RecommendVo> getRecommend(String account, int page){
        RecommendVo data = backendRecommendService.getRecommend(account,page);
        return new ResponseResult<>(SUCCESS,data);
    }

    /**
     * 根据名称搜索
     * @param name
     * @param account
     * @return
     */
    @RequestMapping("findRecommendByName")
    public ResponseResult<ArrayList<Recommend>> findRecommendByName(String name,String account){
        ArrayList<Recommend> data = backendRecommendService.findUserByName(name, account);
        return new ResponseResult<>(SUCCESS,data);
    }




}
